/*
 * @Author: NtyAaron
 * @Date: 2021-04-12 11:13:45
 * @LastEditors: NtyAaron
 * @LastEditTime: 2021-06-23 14:25:59
 * @Description: file content
 * @FilePath: \dwq\pages\check\checkPort\checkPort.js
 */
const app = getApp()
import { getPortList, getPortDetail } from '../../../api/checkPort/checkPort'
import { _t } from '../../../i18n/base'
import { getPosterList } from '../../../api/advert/advert'

Page({
  data: {
    show: false,
    activeNames: [],
    language: '',
    infoReq: {
      language: '',
    },
    portList: [],
    lang: '',
    portDetail: {},
    getAdvertObj: {
      categoryType: '',
      language: '',
      posterName: '',
      posterType: 8,
      showType: 1,
      trafficType: 3,
    },
    bannerList: [],
  },
  // 获取口岸列表
  async getPortList(e) {
    let { result } = await getPortList(e)
    this.setData({
      portList: result,
    })
  },
  async onChange({ detail }) {
    if (detail != '') {
      this.setData({
        portDetail: {},
      })
      let { result } = await getPortDetail(detail)
      this.setData({
        portDetail: result,
        activeNames: detail,
      })
    } else {
      this.setData({
        activeNames: [],
      })
    }
  },
  // 获取广告
  async getPosterList() {
    this.setData({
      'getAdvertObj.language': this.data.language,
    })
    let { result } = await getPosterList(this.data.getAdvertObj)
    if (result) {
      result.map((item) => {
        item.bannerLink = `${app.globalData.host}/attach/showPic?attachId=${item.pic}`
      })
      this.setData({
        bannerList: result,
      })
    }
  },
  // 复制链接
  linkCopyHandle(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.link,
      success: () => {
        wx.showToast({
          title: this.data.lang['已复制网站网址'],
          icon: 'none',
        })
      },
    })
  },
  // 点击广告
  adClickHandle(e) {
    let link = e.currentTarget.dataset.link
    wx.setClipboardData({
      data: link,
      success: () => {
        wx.showToast({
          title: this.data.lang['已复制网站网址'],
          icon: 'none',
        })
      },
    })
  },
  //
  onLoad() {
    this.setData({
      lang: _t(),
      language: wx.getStorageSync('lang'),
      ['infoReq.language']: wx.getStorageSync('lang'),
    })
    this.getPosterList()
    wx.setNavigationBarTitle({
      title: this.data.lang['口岸查询'],
    })
    this.getPortList(this.data.infoReq)
  },
})
